var resourceList = {
	resourceId:null
};

$(function(){
	changeActiveItem('resourceList');
	initTable();
	savehandle();
});

function savehandle(){
	$('#alertdiv').hide();
	$('#alertdiv').savehandle({
		fieldMap:{},
		success:successCallBack,
		successMsg:'删除成功',
		failmsg:'删除失败'
	});
}
/**
 * 资源删除成功刷新信息
 */
function successCallBack(){
	refresh();
}

/**
 * 获取数据
 */
function initTable(){
	$('#grid').grid({
		title:false,
		pager:true,
		checkbox:true,
		multiSelect:true,
		tbar:'#navbar',
		store:{
			url:'/fw/resource/resource_findAll.action',
			idProperty:'resourceId',
			uploadPagesize:'rows'
		},
		pageCfg:{
			btnCount:5
		},
		columns:[
			{cn:'编号',en:'resourceId',width:100,hidden:true},
			{cn:'资源类型',en:'resourceTypeName',width:100},
			{cn:'资源链接',en:'url',width:200},
			{cn:'资源名称',en:'title',width:200}
			]
	}) ;
}
/**
 * 查找
 * 
 */
function search(){
	var title = $('#title').val();
	var url = $('#url').val();
	$('#grid').grid('load',{data:{'title': title, 'url': url}});
}
/**
 * 刷新
 */
function refresh(){
	$('#grid').grid('load',{data:{}});
}
/**
 * 判定单条删除或批量删除
 * @return {TypeName} 
 */
function del(){
	var i = 0;
	var ids = $('#grid').grid('getSelectedIds');
	if(ids.length == 0) {
		$('#alertdiv').savehandle('setmsg',{msg:'请选择要删除的数据!',timer:2000});
		return;
	}else{
		var id = ids.join(",");
		if(confirm("确定要删除这些数据吗？")){
			if(confirm("请再次确认，删除数据后不能恢复！")){
			$.getJSON(
				'/fw/resource/resource_del.action',
				{
					'ids':id
				},
				function(data){
					$('#alertdiv').savehandle('handle',data,2000);
				}
			);
		}
	}
}
}

/**修改打开新页面*/
function edit(){
	var ids = $('#grid').grid('getSelectedIds'),
			id = ids.join(',');
	if(ids.length == 0) {
		$('#alertdiv').savehandle('setmsg',{msg:'请选择要修改的数据!',timer:2000});
		return;
	}else if(ids.length>1){
		$('#alertdiv').savehandle('setmsg',{msg:'只能修改一条数据!',timer:2000});
		return;
	}else{
		resourceList.resourceId = id;
		location.href = "resourceEdit.jsp#"+resourceList.resourceId +',admin';
	}
	
}
/**修改打开新页面*/
function setAuth(){
	var ids = $('#grid').grid('getSelectedIds'),
			id = ids.join(',');
	if(ids.length == 0) {
		$('#alertdiv').savehandle('setmsg',{msg:'请选择要进行资源权限设置的数据!',timer:2000});
		return;
	}else if(ids.length>1){
		$('#alertdiv').savehandle('setmsg',{msg:'只能选择一条数据进行资源权限设置!',timer:2000});
		return;
	}else{
		resourceList.resourceId = id;
		location.href = "resourceAuth.jsp#"+resourceList.resourceId +',admin';
	}
}

/**
 * 添加资源
 */
function add(){
	window.location.href = "resourceAdd.jsp";
}